//
//  SELODPlanet.h
//  Space Explorer
//
//  Created by Yann Blaudin de Thé on 28/04/13.
//  Copyright (c) 2013 TeaTime. All rights reserved.
//

#ifndef __Space_Explorer__SELODPlanet__
#define __Space_Explorer__SELODPlanet__

#include <string>
#include <irrlicht.h>

#include "SEClock.h"
#include "SESpiceManager.h"


class CSampleSceneNode : public irr::scene::ISceneNode
{
private:
	/*
     First, we declare some member variables:
     The bounding box, 4 vertices, and the material of the tetraeder.
     */
	irr::core::aabbox3d<irr::f32> Box;
	irr::video::S3DVertex Vertices[4];
	irr::video::SMaterial Material;
    
	/*
     The parameters of the constructor specify the parent of the scene node,
     a pointer to the scene manager, and an id of the scene node.
     In the constructor we call the parent class' constructor,
     set some properties of the material, and
     create the 4 vertices of the tetraeder we will draw later.
     */
    irr::core::stringw _nom_aff;
    std::string _nom_spice;
    
    SESpice::Object _spice_object;
    
    irr::IrrlichtDevice *_irr_device;
    
    vec3d _position, _velocity;
    
    SpiceDouble _Req, _Rpo;
    
public:
    
	CSampleSceneNode(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id, const irr::core::stringw& disp_name, const std::string& spice_name, irr::video::ITexture* ground_tex, irr::video::ITexture* cloud_tex, irr::video::ITexture* normal_tex);
    
	/*
     Before it is drawn, the irr::scene::ISceneNode::OnRegisterSceneNode()
     method of every scene node in the scene is called by the scene manager.
     If the scene node wishes to draw itself, it may register itself in the
     scene manager to be drawn. This is necessary to tell the scene manager
     when it should call irr::scene::ISceneNode::render(). For
     example, normal scene nodes render their content one after another,
     while stencil buffer shadows would like to be drawn after all other
     scene nodes. And camera or light scene nodes need to be rendered before
     all other scene nodes (if at all). So here we simply register the
     scene node to render normally. If we would like to let it be rendered
     like cameras or light, we would have to call
     SceneManager->registerNodeForRendering(this, SNRT_LIGHT_AND_CAMERA);
     After this, we call the actual
     irr::scene::ISceneNode::OnRegisterSceneNode() method of the base class,
     which simply lets also all the child scene nodes of this node register
     themselves.
     */
	virtual void OnRegisterSceneNode();
    
	/*
     In the render() method most of the interesting stuff happens: The
     Scene node renders itself. We override this method and draw the
     tetraeder.
     */
	virtual void render();
    
	/*
     And finally we create three small additional methods.
     irr::scene::ISceneNode::getBoundingBox() returns the bounding box of
     this scene node, irr::scene::ISceneNode::getMaterialCount() returns the
     amount of materials in this scene node (our tetraeder only has one
     material), and irr::scene::ISceneNode::getMaterial() returns the
     material at an index. Because we have only one material here, we can
     return the only one material, assuming that no one ever calls
     getMaterial() with an index greater than 0.
     */
	virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const
    {
        return Box;
    }
    
	virtual irr::u32 getMaterialCount() const;
    
	virtual irr::video::SMaterial& getMaterial(irr::u32 i);
};

#endif /* defined(__Space_Explorer__SELODPlanet__) */
